//
//  LRFunction.m
//  本地生活圈
//
//  Created by admin on 15/8/10.
//  Copyright (c) 2015年 懒人. All rights reserved.
//

#import "LRFunction.h"
#import "MD5.h"
#import "NSString+Hash.h"

@implementation LRFunction

+ (NSString *)getTimeScamp
{
    return [NSString stringWithFormat:@"%f",[[NSDate date]timeIntervalSince1970]];
}

+ (NSString *)md5StringFromArray:(NSArray *)array
{
    NSMutableString *str = [NSMutableString string];
    [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        [str appendString:obj];
    }];
//    return str.md5String;
    return [MD5 MD5Encrypt:str];
}

+ (void)saveBool:(BOOL)b key:(NSString *)key
{
    if (key.length <= 0 || key == nil) return ;
    [[NSUserDefaults standardUserDefaults] setBool:b forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (UIImageView *)getImageWithUrlString:(NSString *)urlStr placeholderImage:(UIImage *)image
{
    UIImageView *imgView = [[UIImageView alloc]init];
    [imgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:image];
    return imgView;
}

+ (void)saveUserInfoWithDict:(NSDictionary *)dict
{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *filePath = [path stringByAppendingPathComponent:@"userInfo.dog"];
    [dict writeToFile:filePath atomically:YES];
}

+ (NSDictionary *)getUserInfo
{
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *filePath = [path stringByAppendingPathComponent:@"userInfo.dog"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
    return dict;
}

+ (NSURL *)getUrlWithString:(NSString *)str
{
    return [NSURL URLWithString:str];
}

+ (void)hidenTabBarView:(BOOL)b
{
    // 隐藏tabbar
    UIApplication *app = [UIApplication sharedApplication];
    LRTabBarViewController *tabBar = (LRTabBarViewController *)app.keyWindow.rootViewController;
    tabBar.tabBarView.hidden = b;
}
@end
